﻿namespace ProblemsSet
{
    public class Problem_132 : BaseProblem
    {
        public override object GetResult()
        {
            const int max = 1000000000;
            const int count = 40;

            long res = 0;
            long cnt = 0;

            for (long n = 7; n <= long.MaxValue; n+=2 )
            {
                var tmp = MathLogic.GetAForPrimes(n, max);
                if (tmp < 0 || tmp > max) continue;
                if (max%tmp != 0) continue;
                res += n;
                cnt++;
                if (cnt == count)
                    return res;
            }

            return res;
        }

        public override string Problem
        {
            get
            {
                return @"A number consisting entirely of ones is called a repunit. We shall define R(k) to be a repunit of length k.

For example, R(10) = 1111111111 = 11412719091, and the sum of these prime factors is 9414.

Find the sum of the first forty prime factors of R(109).";
            }
        }

        public override bool IsSolved
        {
            get
            {
                return true;
            }
        }

        public override object Answer
        {
            get
            {
                return 843296;
            }
        }
    }
}
